﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="QuanLyDanhMuc.ascx.cs" Inherits="TraCuuTinRaoVat.UserControl.QuanLyDanhMuc"%>

<table>
<tr>
    <td>
        <h4><asp:Label ID="Label2" runat="server" Text="DANH MỤC CHÍNH"></asp:Label></h4>
    </td>
    <td>&nbsp;</td>
    <td>
        <h4><asp:Label ID="Label3" runat="server" Text="DANH MỤC CON"></asp:Label></h4>
    </td>
    </tr>
  <tr>
    <td>
        <table>
            <tr>
                <td>
                    <br />
                    Tên:<br />
                    <br />
                </td>
                <td>
        <asp:TextBox ID="txtTenDanhMuc" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valiTenDM" runat="server" 
        ValidationGroup = "Form1"
            ControlToValidate="txtTenDanhMuc" ErrorMessage="*"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
        <asp:Button ID="btnThemDanhMucCon0" runat="server" onclick="Button2_Click" 
            Text="Thêm" ValidationGroup="Form1" CssClass="exclusive" />
                </td>
                <td>
            <asp:Button ID="Button2" runat="server" Text="Hủy bỏ" onclick="Button2_Click1" CssClass="exclusive"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
        <asp:Label ID="lblResultChinh" runat="server" Font-Bold="True" 
            ForeColor="Red"></asp:Label>
                    <br />
            <br />
                </td>
            </tr>
        </table>
      </td>
    <td>&nbsp;</td>
    <td>

<table >
    <tr>
        <td class="style2">
            Mục chính:</td>
        <td class="style3">
            <asp:DropDownList ID="DropDownList1" runat="server" 
                DataSourceID="SqlDataSource1" DataTextField="TenDanhMucChinh" 
                DataValueField="TenDanhMucChinh" Height="23px" Width="134px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:RAOVATConnectionString %>" 
                SelectCommand="SELECT [TenDanhMucChinh] FROM [DANH_MUC_CHINH]">
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td>
            Mục con&nbsp; :</td>
        <td>
            <asp:TextBox ID="txtTenDanhMucCon" 
            runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="valiTenDMCon" runat="server" 
        ValidationGroup = "Form2"
            ControlToValidate="txtTenDanhMucCon" ErrorMessage="*"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td >
        <asp:Button ID="btnThemDanhMucCon" runat="server" onclick="btnDmCon_Click" CssClass="exclusive"
            Text="Thêm" ValidationGroup="Form2" />
        </td>
        <td>
            <asp:Button ID="Button1" runat="server" Text="Hủy bỏ" CssClass="exclusive"
                onclick="btnHuyCon_Click" />
        </td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: center">
        <asp:Label ID="lblResultCon" runat="server" ForeColor="#FF5050"></asp:Label>
            <br />
            <br />
        </td>
    </tr>
</table>

      </td>
  </tr>
    <tr>
    <td>
        <asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="MaDanhMucChinh" DataSourceID="SqlDataSource4" 
            EnableModelValidation="True" CellPadding="4" ForeColor="#333333" 
            GridLines="None" AllowPaging="True" Width="344px">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink2" runat="server" 
                            NavigateUrl='<%# Eval("MaDanhMucChinh", @"~\Admin\FrmQuanLyDanhMuc.aspx?MaDanhMucChinh={0}") %>' 
                            ToolTip="Xem danh sách danh mục con">Select</asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="TenDanhMucChinh" HeaderText="Tên danh mục chính" 
                    SortExpression="TenDanhMucChinh" />
                <asp:TemplateField HeaderText="Đã xóa" SortExpression="Deleted">
                    <EditItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Deleted") %>' />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Deleted") %>' 
                            Enabled="false" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#666666" Font-Bold="True" ForeColor="White" 
                Height="40px" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#CCCCCC" Height="40px" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
            ConnectionString="<%$ ConnectionStrings:RAOVATConnectionString %>" 
            DeleteCommand="DELETE FROM [DANH_MUC_CHINH] WHERE [MaDanhMucChinh] = @MaDanhMucChinh" 
            InsertCommand="INSERT INTO [DANH_MUC_CHINH] ([TenDanhMucChinh], [Deleted]) VALUES (@TenDanhMucChinh, @Deleted)" 
            SelectCommand="SELECT * FROM [DANH_MUC_CHINH]" 
            UpdateCommand="UPDATE [DANH_MUC_CHINH] SET [TenDanhMucChinh] = @TenDanhMucChinh, [Deleted] = @Deleted WHERE [MaDanhMucChinh] = @MaDanhMucChinh">
            <DeleteParameters>
                <asp:Parameter Name="MaDanhMucChinh" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="TenDanhMucChinh" Type="String" />
                <asp:Parameter Name="Deleted" Type="Boolean" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="TenDanhMucChinh" Type="String" />
                <asp:Parameter Name="Deleted" Type="Boolean" />
                <asp:Parameter Name="MaDanhMucChinh" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        </td>
    <td>&nbsp;</td>
    <td>
        <asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="MaDanhMucCon" DataSourceID="SqlDataSource5" 
            EnableModelValidation="True" CellPadding="4" ForeColor="#333333" 
            GridLines="None" AllowPaging="True" Width="372px">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
               
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                </asp:TemplateField>
                     <asp:BoundField DataField="TenDanhMucChinh" HeaderText="Tên danh mục chính" 
                    SortExpression="TenDanhMucChinh" ReadOnly="True" />
                   
                <asp:BoundField DataField="TenDanhMucCon" HeaderText="Tên danh mục con" 
                    SortExpression="TenDanhMucCon" />
                <asp:CheckBoxField DataField="Deleted" HeaderText="Đã xóa" 
                    SortExpression=" Deleted" />
               
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#666666" Font-Bold="True" ForeColor="White" 
                Height="40px" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#CCCCCC" Height="40px" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
            ConnectionString="<%$ ConnectionStrings:RAOVATConnectionString %>" 
            DeleteCommand="DELETE FROM [DANH_MUC_CON] WHERE [MaDanhMucCon] = @MaDanhMucCon" 
            InsertCommand="INSERT INTO [DANH_MUC_CON] ([MaDanhMucChinh], [TenDanhMucCon], [Deleted]) VALUES (@MaDanhMucChinh, @TenDanhMucCon, @Deleted)" 
            SelectCommand="SELECT DANH_MUC_CON.MaDanhMucCon, DANH_MUC_CON.MaDanhMucChinh, DANH_MUC_CON.TenDanhMucCon, DANH_MUC_CON.Deleted, DANH_MUC_CHINH.TenDanhMucChinh FROM DANH_MUC_CON INNER JOIN DANH_MUC_CHINH ON DANH_MUC_CON.MaDanhMucChinh = DANH_MUC_CHINH.MaDanhMucChinh WHERE (DANH_MUC_CON.MaDanhMucChinh = @MaDanhMucChinh)" 
        
            UpdateCommand="UPDATE [DANH_MUC_CON] SET  [TenDanhMucCon] = @TenDanhMucCon, [Deleted] = @Deleted WHERE [MaDanhMucCon] = @MaDanhMucCon">
            <DeleteParameters>
                <asp:Parameter Name="MaDanhMucCon" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="MaDanhMucChinh" Type="Int32" />
                <asp:Parameter Name="TenDanhMucCon" Type="String" />
                <asp:Parameter Name="Deleted" Type="Boolean" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="1" Name="MaDanhMucChinh" 
                    QueryStringField="MaDanhMucChinh" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="MaDanhMucChinh" Type="Int32" />
               <asp:Parameter Name="Deleted" Type="Boolean" />
                <asp:Parameter Name="MaDanhMucCon" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        </td>
    </tr>
    </table>